package listiterator;

/**
 * Created by 5406160@qq.com on LiBoWen 李博闻.
 *
 * @ClassName : ListIteratorDemo1
 * @Author : 54061
 * @Date: 2022/2/12 14:10
 */
import java.util.ArrayList;
import java.util.List;
import java.util.ListIterator;

public class ListIteratorDemo1 {
    public static void main(String[] args) {
        List<String> list = new ArrayList<>();
        //直接创建列表迭代器对象
        ListIterator<String> lit = list.listIterator();
        lit.add("张三");
        lit.add("李四");
        lit.add("王五");
        System.out.println("list = " + list);
        //迭代器遍历集合
        while (lit.hasNext()){
            System.out.println("========================");
            String name = lit.next();
            if (name.equals("李四")){
                lit.add("赵六");
            }
        }
        System.out.println("list = " + list);
    }
}
